#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 10, M = 2 * N;
int n, q;
int h[N], e[M], ne[M], idx, w[M];
int f[N][22], dis[N];
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u, int fa)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		dis[j] = dis[u] + 1;
		f[j][0] = u;
		for (int k = 1; (1 << k) <= dis[j]; k++) {
			f[j][k] = f[f[j][k - 1]][k - 1];
		}
		dfs(j, u);
	}
}

int lca(int a, int b)
{
	if (dis[a] < dis[b])swap(a, b);
	int d = dis[a] - dis[b];
	for (int i = 0; d; i++) {
		if (d & 1)a = f[a][i];
		d /= 2;
	}
	if (a == b)return a;
	for (int i = 21; i >= 0; i--) {
		if (f[a][i] != f[b][i]) {
			a = f[a][i];
			b = f[b][i];
		}
	}
	return f[a][0];
}
int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		add(u, v);
		add(v, u);
	}
	dfs(1, 0);
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		int k = lca(u, v);
		cout << dis[u] + dis[v] - 2 * dis[k] + 1 << endl;
	}
	return 0;
}